package com.syg.servlet08_getRespHTML;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

public class _04_HtmlBuffer {
    private static class HtmlInfo extends ThreadLocal {

        private Map values = Collections.synchronizedMap(new HashMap());

        public Object initialValue() {
            return new String();
        }

        public String getHtmlStr() {
            return (String) this.get();
        }

        public Object get() {
            Thread curThread = Thread.currentThread();
            Object o = values.get(curThread);
            if (o == null && !values.containsKey(curThread)) {
                o = initialValue();
                values.put(curThread, o);
            }
            return o;
        }

        public void set(Object newValue) {
            values.put(Thread.currentThread(), newValue);
        }
    }

    private static HtmlInfo htmlInfo = new HtmlInfo();

    public static void cleanStr(){
        htmlInfo.set("");
    }

    public static void addStr(String htmlStr) {
        String htmlstr = (String)htmlInfo.get();
        if(htmlstr == null) htmlstr ="";
        htmlstr += htmlStr;
        htmlInfo.set(htmlstr);
    }

    public static String getStr() {
        return (String)htmlInfo.get();
    }
}
